import base64
import pickle


def encrypt(obj):
    """
    cookies 加密
    :param plain: python对象
    :return: 密文字符串
    """
    if not obj:
        return ''

    cipher_b = pickle.dumps(obj)
    cipher_b64 = base64.b64encode(cipher_b)

    return cipher_b64.decode()


def decrypt(cipher):
    """
    cookies 解密
    :param cipher: 密文
    :return: python对象
    """

    if not cipher or cipher == 'None':
        return

    cipher_b64 = cipher.encode()
    cipher_b = base64.b64decode(cipher_b64)

    return pickle.loads(cipher_b)
